package desgin.pattern.structure.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * 　当客户端需要单纯享元对象的时候，需要调用享元工厂的factory()方法， 并传入所需的单纯享元对象的内蕴状态，由工厂方法产生所需要的享元对象。
 * 
 * @author shuai.zuo
 * @date 2015年3月3日
 */
public class FlyWeightFactory {
	private Map<Character, FlyWeight> files = new HashMap<Character, FlyWeight>();

	public FlyWeight factory(Character state) {
		FlyWeight f = files.get(state);
		if (null == f) {
			f = new ConcreteFiyweight(state);
			files.put(state, f);
		}
		return f;
	}

}
